//
//  LZUserCenterCollectAndCommentPresenter.m
//  laziz_Consumer
//
//  Created by xbnzd on 16/11/22.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZUserCenterCollectAndCommentPresenter.h"
#import "NetworkServiceManager.h"
#import "LZUserModel.h"
#import "LAReviewModel.h"
#import "LZMyFavoriteModel.h"
#import "LZRestaurantListModel.h"
#import "LZVideoListModel.h"
#import "MJExtension.h"

extern NSString *customer;

static NSString *kWaitCommentListUrl = @"/clientcustomerNotRemark/myListPage"; //我的待点评 列表
static NSString *kUserCollectListUrl = @"/clientcustomerFavorite/listPage";    //我的收藏列表
static NSString *kUserVideoCommentListUrl = @"/clientvideoComments/myListPage"; //我的视频评论列表
static NSString *kUserRestaurantCommentListUrl = @"/clientrestaurantComments/myListPage";  //我的餐厅评论列表

@implementation LZUserCenterCollectAndCommentPresenter

/**
 我的待点评列表
 
 @param successBlock <#successBlock description#>
 @param failedBlock <#failedBlock description#>
 */
+ (void)getUserWaitCommentListWithType:(NSString *)type PageNum:(int)pageNum PageLimit:(int)pageLimit andPrameter:(NSDictionary*)prameter ResultSuccess:(void (^)(NSArray *,NSString *))successBlock ResultFailed:(void (^)(NSString *))failedBlock
{
    if ([LZUserModel Instance].userId.length == 0) {
        if (failedBlock) {
            failedBlock(@"用户未登录,请登录后操作");
        }
        
        return;
    }
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",customer,kWaitCommentListUrl];
    
    NSMutableDictionary *dic = [@{
                          @"token" : [LZUserModel Instance].userToken,
                          @"commentType":type,
                          @"cpage" : [NSNumber numberWithInt:pageNum],
                          @"limit" : [NSNumber numberWithInt:pageLimit]
                          } mutableCopy];
    dic[@"removeCnt"] = prameter[@"removeCnt"];
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        if ([resultData[@"statusCode"] integerValue] == kCodeSuccesss) {
            
            NSMutableArray *arrData = [NSMutableArray array];
            NSArray *arrResult = resultData[@"data"][@"list"];
            for (int i = 0; i<arrResult.count; i++) {
                // 视频
                LZVideoListModel *model = [LZVideoListModel mj_objectWithKeyValues:arrResult[i]];
                
                if (model) {
                    [model refreshToBeReviewListModel];
                    [arrData addObject:model];
                }
            }
            
            if (successBlock) {
                successBlock(arrData,resultData[@"timestamp"]);
            }
        }else{
            NSString *str = resultData[@"statusCode"];
            [LZBasePresenter checkAuthorStatus:str];
            if (failedBlock) {
                failedBlock(str);
            }
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        if (failedBlock) {
            failedBlock(@"网络错误,请稍后再试");
        }
    }];
}




/**
 我的收藏列表
 
 @param type 0 餐厅     1 视频
 @param pageNum 页数
 @param pageLimit 每页几条
 @param prameter 其他信息字典
 @param successBlock <#successBlock description#>
 @param failedBlock <#failedBlock description#>
 */
+ (void)getUserCollectListWithType:(NSString *)type PageNum:(int)pageNum PageLimit:(int)pageLimit andPrameter:(NSDictionary*)prameter ResultSuccess:(void (^)(NSArray *,NSString *))successBlock ResultFailed:(void (^)(NSString *))failedBlock
{
    if ([LZUserModel Instance].userToken.length == 0) {
        [LZBasePresenter pushLoginViewController];
        if (failedBlock) {
            failedBlock(@"用户未登录,请登录后操作");
        }
        
        return;
    }
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",customer,kUserCollectListUrl];
    NSMutableDictionary *dic = [@{
                          @"token" : [LZUserModel Instance].userToken,
                          @"favoriteType" : type,
                          @"cpage" : [NSNumber numberWithInt:pageNum],
                          @"limit" : [NSNumber numberWithInt:pageLimit],
                          } mutableCopy];
    [dic setObject:prameter[@"removeCnt"] forKey:@"removeCnt"];
    
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        if ([resultData[@"statusCode"] integerValue] == kCodeSuccesss) {
            
            
            NSMutableArray *arrData = [NSMutableArray array];
            NSArray *arrResult = resultData[@"data"][@"list"];
            for (int i = 0; i<arrResult.count; i++) {
                LZMyFavoriteModel *model = [LZMyFavoriteModel mj_objectWithKeyValues:arrResult[i]];
                
                // 餐厅
                LZRestaurantListModel *restaurant_model = model.restaurantDTO;
                if (restaurant_model) {
                    [restaurant_model changeCuisineNameByCuisineID];
                    restaurant_model.restaurantId = model.sellerId;
                    restaurant_model.isStore = YES;
                }
                
                // 视频
                LZVideoListModel *video_model = model.videoDTO;
                if (video_model) {
                    video_model.videoId = model.promotionId;
                    video_model.sellerId = model.sellerId;
                    video_model.isStore = YES;
                }
                
                if (model) {
                    [arrData addObject:model];
                }
            }
            
            
            if (successBlock) {
                successBlock(arrData,resultData[@"timestamp"]);
            }
        }else{
            NSString *str = resultData[@"statusCode"];
            [LZBasePresenter checkAuthorStatus:str];
            if (failedBlock) {
                failedBlock(str);
            }
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        if (failedBlock) {
            failedBlock(@"网络错误,请稍后再试");
        }
    }];
}



/**
 我的视频评论列表
 
 @param pageNum 页数
 @param pageLimit 每页数量
 @param successBlock <#successBlock description#>
 @param failedBlock <#failedBlock description#>
 */
+ (void)getUserVideoCommentListWithPageNum:(int)pageNum PageLimit:(int)pageLimit ResultSuccess:(void (^)(NSArray *,NSString *))successBlock ResultFailed:(void (^)(NSString *))failedBlock
{
    
    if ([LZUserModel Instance].userToken.length == 0) {
        [LZBasePresenter pushLoginViewController];
        if (failedBlock) {
            failedBlock(@"用户未登录,请登录后操作");
        }
        
        return;
    }
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",customer,kUserVideoCommentListUrl];
    NSDictionary *dic = @{
                          @"token" : [LZUserModel Instance].userToken,
                          @"cpage" : [NSNumber numberWithInt:pageNum],
                          @"limit" : [NSNumber numberWithInt:pageLimit]
                          };
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        if ([resultData[@"statusCode"] integerValue] == kCodeSuccesss) {
            NSMutableArray *arrData = [NSMutableArray array];
            NSArray *arrResult = resultData[@"data"][@"list"];
            for (int i = 0; i<arrResult.count; i++) {
                LAReviewModel *model = [LAReviewModel mj_objectWithKeyValues:arrResult[i]];
                [arrData addObject:model];
            }
            if (successBlock) {
                successBlock(arrData,resultData[@"timestamp"]);
            }
        }else{
            NSString *str = resultData[@"statusCode"];
            [LZBasePresenter checkAuthorStatus:str];
            if (failedBlock) {
                failedBlock(str);
            }
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        if (failedBlock) {
            failedBlock(@"网络错误,请稍后再试");
        }
    }];
}




/**
 我的餐厅评论列表
 
 @param pageNum 页数
 @param pageLimit 每页数量
 @param successBlock <#successBlock description#>
 @param failedBlock <#failedBlock description#>
 */
+ (void)getUserRestaurantCommentListWithPageNum:(int)pageNum PageLimit:(int)pageLimit ResultSuccess:(void (^)(NSArray *,NSString *))successBlock ResultFailed:(void (^)(NSString *))failedBlock
{
    
    if ([LZUserModel Instance].userToken.length == 0) {
        [LZBasePresenter pushLoginViewController];
        if (failedBlock) {
            failedBlock(@"用户未登录,请登录后操作");
        }
        
        return;
    }
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",customer,kUserRestaurantCommentListUrl];
    NSDictionary *dic = @{
                          @"token" : [LZUserModel Instance].userToken,
                          @"cpage" : [NSNumber numberWithInt:pageNum],
                          @"limit" : [NSNumber numberWithInt:pageLimit]
                          };
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        if ([resultData[@"statusCode"] integerValue] == kCodeSuccesss) {
            NSMutableArray *arrData = [NSMutableArray array];
            NSArray *arrResult = resultData[@"data"][@"list"];
            for (int i = 0; i<arrResult.count; i++) {
                LAReviewModel *model = [LAReviewModel mj_objectWithKeyValues:arrResult[i]];
                [arrData addObject:model];
            }
            if (successBlock) {
                successBlock(arrData,resultData[@"timestamp"]);
            }
        }else{
            NSString *str = resultData[@"statusCode"];
            [LZBasePresenter checkAuthorStatus:str];
            if (failedBlock) {
                failedBlock(str);
            }
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        if (failedBlock) {
            failedBlock(@"网络错误,请稍后再试");
        }
    }];
}










@end
